package com.warthur.jfinal.demo.common;

import lombok.AccessLevel;
import lombok.NoArgsConstructor;

/**
 * @author warthur
 * @date 2019/10/07
 */
@NoArgsConstructor(access = AccessLevel.PRIVATE)
public final class ResponseUtils {

    public static Response success(Object data) {
        return success(ErrorCode.REQUEST_SUCCESS, data);
    }

    public static Response success(ErrorCode errorCode, Object data) {
        return new Response<>(errorCode.getCode(), errorCode.getMsg(), data);
    }

    public static Response error(int code, String message) {
        return new Response<>(code, message);
    }

    public static Response error(String message) {
        return error(ErrorCode.REQUEST_ERROR.getCode(), message);
    }

    public static Response error(ErrorCode errorCode) {
        return error(errorCode.getCode(), errorCode.getMsg());
    }

    public static Response error(ErrorCode errorCode, Object data) {
        return success(errorCode, data);
    }
}
